﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entities;
using Utility;
using BUS;

public partial class A_LetsDeal_dangkythanhvien : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void bt_timkiem_Click(object sender, EventArgs e)
    {
        if (txt_timkiem.Text != "")
        {
            Response.Redirect("~/A_LetsDeal/Default.aspx?tensanpham=" + txt_timkiem.Text);
        }
    }
    protected void bt_kiemtra_Click(object sender, EventArgs e)
    {
        int khachhang = Tbl_KhachHang_BUS.TestUsername(txt_tendangnhap.Text);
        if (khachhang == 1)
        {
            lit_error.Text = "<font color='red'>Tên tài khoản đã tồn tại</font>";
        }
        else
        {
            lit_error.Text = "<font color='red'>Có thể sử dụng tên này</font>";
        }

    }
    protected void lbt_dathang_Click(object sender, EventArgs e)
    {
        if (txt_tendangnhap.Text != "" && txt_pass.Text != "" &&
            txt_pass.Text != "" && txt_hoten.Text != "" && txt_dc.Text != "" &&
            txt_sdt.Text != "" && txt_email.Text != "")
        {
            int kh = Tbl_KhachHang_BUS.TestUsername(txt_tendangnhap.Text);
            if (kh == 1)
            {
                lit_error.Text = "<font color='red'>Tên tài khoản đã tồn tại</font>";
            }
            else
            {
                Tbl_KhachHang_Entities khachhang = new Tbl_KhachHang_Entities();
                khachhang.TaiKhoan = txt_tendangnhap.Text;
                khachhang.MatKhau = txt_pass.Text;
                khachhang.HoTen = txt_hoten.Text;
                khachhang.DiaChi = txt_dc.Text;
                khachhang.SDT = txt_sdt.Text;
                khachhang.Email = txt_email.Text;
                khachhang.Sodutaikhoan = 0;
                khachhang.LoaiTK = 2;
                Tbl_KhachHang_BUS.Insert(khachhang);
                hyp_back.Text = "Đăng ký thành công !";
                hyp_back.NavigateUrl = "~/A_LetsDeal/Default.aspx";
                hyp_back.Visible = true;
            }

        }
    }
}
